package com.bloveoacom.weichi.presenter;


import com.bloveoacom.base.UserInfoBean;
import com.bloveoacom.http.RxHelper;
import com.bloveoacom.observer.BaseSubscriber2;
import com.bloveoacom.weichi.bean.UserBean;
import com.bloveoacom.weichi.contract.MineContract;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/8/22
 * desc  : 我的
 */
public class MinePresenter extends MineContract.Presenter {



    @Override
    public void loadFirstData(boolean isRefresh) {
        mView.getOps(mModel.getOps());
        if(UserInfoBean.getInstance().isLogin()){
            getUserInfo();
        }
        mView.finishRefresh();
    }
    @Override
    public void loadMoreData() {

    }

    @Override
    public void getUserInfo() {
        BaseSubscriber2<UserBean> baseSubscriber2 = mModel.getUserInfo().compose(RxHelper.getData()).subscribeWith(new BaseSubscriber2<UserBean>() {
            @Override
            public void onNext(UserBean o) {
                super.onNext(o);
                mView.setUserInfo(o);
            }
        });
        addDispose(baseSubscriber2);
    }

    @Override
    public void userSignIn(String token) {
        BaseSubscriber2<Object> baseSubscriber2 = mModel.userSignIn().compose(RxHelper.getData()).subscribeWith(new BaseSubscriber2<Object>(mView) {
            @Override
            public void onNext(Object o) {
                super.onNext(o);
                mView.userSignIn(o);
            }
        });
        addDispose(baseSubscriber2);
    }
}
